package com.it.jobs;

import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TestRedisValue {
    @Autowired
    private JedisPool jedisPool;

    public void sava_value_redis() {
        long current_time = System.currentTimeMillis();


        //获取redis中的数据
        //如果有数据 对数据进行加1 没有则重新添加
        String a = jedisPool.getResource().hget("test", "a");
        try{
            if (a != null) {
                int b = Integer.parseInt(a);
                System.out.println("redis中取出来的值"+b);
                b = b+1;
                String c = String.valueOf(b);
                jedisPool.getResource().hset("test", "a", c);
            } else {
                jedisPool.getResource().hset("test", "a", "1");
            }

        }catch (Exception e){

            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒");

            Date date = new Date(current_time);
            System.out.println(dateFormatter.format(date)+current_time+"定时任务出现异常:"+e);
        }


    }
}